#include <bits/stdc++.h>

using namespace std;
#define int long long
const int inf = 0x3f3f3f3f;

void solve()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<int> c1(n, 0), c2(n, 0);
    for (int i = 0; i < n; i++)
    {
        int d1 = (i % 2 == 0) ? 1 : 0;
        int d2 = (i % 2 == 0) ? 0 : 1;
        int cur = a[i] % 2;
        c1[i] = (cur == d1) ? 0 : 1;
        c2[i] = (cur == d2) ? 0 : 1;
    }
    vector<int> pre1(n + 1, 0), pre2(n + 1, 0);
    for (int i = 0; i < n; i++)
    {
        pre1[i + 1] = pre1[i] + c1[i];
        pre2[i + 1] = pre2[i] + c2[i];
    }
    int ans = 1e18;
    for (int i = 0; i <= n - m; i++)
    {
        int sum1 = pre1[i + m] - pre1[i];
        int sum2 = pre2[i + m] - pre2[i];
        ans = min(ans, min(sum1, sum2));
    }
    cout << ans << endl;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int _ = 1;
    //cin >> _;
    while (_--)
    {
        solve();
    }
    return 0;
}